package com.zsz.dao.impl;

import com.zsz.Util.MybatisUtils;
import com.zsz.dao.StudentDao;
import com.zsz.domain.Student;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentDaolmpl implements StudentDao {
    @Override
    public List<Student> selectStudents() {
        //获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String sqlId="com.zsz.dao.StudentDao.selectStudents";



        //执行sql语句，使用SqlSession类的方法。
        List<Student> students= sqlSession.selectList(sqlId);

        //关闭
        sqlSession.close();

        return students;
    }

    @Override
    public int insertStudent(Student student) {
        //获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String sqlId="com.zsz.dao.StudentDao.insertStudent";

        //执行sql语句，使用SqlSession类的方法。

        int num= sqlSession.insert(sqlId,student);

        //提交事务
        sqlSession.commit();
        //关闭
        sqlSession.close();
        return num;
    }
}
